﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using WebAppTemplate.CSR.Repository.DbContexts;

namespace WebAppTemplate.CSR.Service.Commands
{
    public record DeleteDemoCommand(long Id) : IRequest<bool>;

    public class DeleteDemoCommandHandler : IRequestHandler<DeleteDemoCommand, bool>
    {
        private readonly AppDbContext _dbContext;
        public DeleteDemoCommandHandler(AppDbContext dbContext) => _dbContext = dbContext;

        public async Task<bool> Handle(DeleteDemoCommand request, CancellationToken cancellationToken)
        {
            await _dbContext.Demo.Where(it => it.Id == request.Id).ExecuteDeleteAsync(cancellationToken);

            return true;
        }
    }
}
